package com.itheima.chap02;

public class ConvertDemo {
    public static void main(String[] args) {
        String content = "   he really pulled his head out of his ass and did a decent job today," +
                "considering the shit he usually puts out." + "thank God"  ;
        System.out.println(convert(content));
    }

    final static String[] sensetiveWords = {"shit" , "ass"};
    private static String convert(String content) {
        String result = content;
        if (content == null || content.isEmpty()){
            return "";
        }
        // 1.去除两端空格
        result = result.strip();
        // 2.遍历敏感词数组，替换敏感词
        for (int i = 0; i < sensetiveWords.length; i++) {
//            String word = sensetiveWords[i];
            result = result.replace(sensetiveWords[i], "*".repeat(sensetiveWords[i].length()));
        }
        // 3.首字母大写
        String[] sentence = result.split("[.!?]+");
        for (int i = 0; i < sentence.length; i++) {
            String word = sentence[i];
            String firstLetter = word.substring(0, 1).toUpperCase();
            sentence[i] = firstLetter + word.substring(1);
            System.out.println(sentence[i]);
        }
        return "";
    }

}
